Production: Add Stack Name to our Application
We will add the stack name to our Hello World application in this lesson so that our application will know what environment it is running in.
We'll cover the following
In the real world, we will generally want to have at least one environment to test our application and infrastructure before rolling changes out to production. A common model is to call the testing environment ‘staging’ and production ‘prod’. We’ll set these up next.
In this and upcoming two lessons, we will decommission our existing infrastructure and replace it with two CloudFormation nested stacks representing our staging and prod environments. We will also update our CodePipeline so that it will promote updates to prod only after they’ve successfully passed through staging.
Adding the stack name to Hello World#
Let’s start by making a small change to the start-service.sh
script so that our application will know what environment it is running in.
Then, we also need to update the start
script in package.json
to pass the stack name environment variable to the application.
Now, let’s change the response in server.js
to include the stack name.
Let’s push these changes to GitHub.
Finally, let’s wait for the changes to go through the pipeline, and we should see our stack name when we hit our application’s endpoint.
Now in the next lesson, we will create our nested stack for staging.